package com.thinkgem.jeesite.modules.bu.utils;

import java.io.FileOutputStream;
import java.util.Date;

import org.apache.poi.hssf.usermodel.HSSFCell;
import org.apache.poi.hssf.usermodel.HSSFCellStyle;
import org.apache.poi.hssf.usermodel.HSSFFont;
import org.apache.poi.hssf.usermodel.HSSFRichTextString;
import org.apache.poi.hssf.usermodel.HSSFRow;
import org.apache.poi.hssf.usermodel.HSSFSheet;
import org.apache.poi.hssf.usermodel.HSSFWorkbook;
import org.apache.poi.hssf.util.CellRangeAddress;
import org.apache.poi.ss.usermodel.Cell;
import org.apache.poi.ss.usermodel.Row;

public class CreateXml {

	private void cteateCell(HSSFWorkbook wb, HSSFRow row, short col, String val) {
		HSSFCell cell = row.createCell(col);
		cell.setCellValue(val);
		HSSFCellStyle cellstyle = wb.createCellStyle();
		cellstyle.setAlignment(HSSFCellStyle.ALIGN_CENTER_SELECTION);
		cell.setCellStyle(cellstyle);
	}

	public static void main(String argv[]) {
		try {
			// 创建新的Excel 工作簿
			HSSFWorkbook workbook = new HSSFWorkbook();

			// 设置字体
			HSSFFont font = workbook.createFont();
			font.setBoldweight(HSSFFont.BOLDWEIGHT_BOLD);
			font.setFontHeightInPoints((short) 14);

			// 设置样式
			HSSFCellStyle cellStyle = workbook.createCellStyle();
			cellStyle.setFont(font);
			cellStyle.setAlignment(HSSFCellStyle.ALIGN_CENTER);

			// 在Excel工作簿中建一工作表，其名为缺省值
			// 如要新建一名为"月报表"的工作表，其语句为：
			HSSFSheet sheet = workbook.createSheet("工艺");
			
			HSSFRow row = sheet.createRow(0);
			HSSFCell c0 = row.createCell(0);
			c0.setCellValue(new HSSFRichTextString("xxxx"));
			
			HSSFCell c1 = row.createCell(1);
			c1.setCellValue(new HSSFRichTextString("?????"));
			
			HSSFRow row1 = sheet.createRow(1);
			HSSFCell c5 = row1.createCell(3);
			c5.setCellValue(new HSSFRichTextString("客户:"));
			HSSFCell c6 = row1.createCell(4);
			c6.setCellValue(new HSSFRichTextString(""));


			sheet.addMergedRegion(new CellRangeAddress(0, 1, 0, 11));
			sheet.addMergedRegion(new CellRangeAddress(0, 0, 12, 13));
			
			// 新建一输出文件流
			FileOutputStream fOut = new FileOutputStream("E:/excel/" + new Date().getTime() + ".xls");
			// 把相应的Excel 工作簿存盘
			workbook.write(fOut);
			fOut.flush();
			// 操作结束，关闭文件
			fOut.close();
			System.out.println("文件生成...");
		} catch (Exception e) {
			System.out.println("已运行 xlCreate() : " + e);
		}
	}

	public static HSSFCell getCellInSheet1(HSSFWorkbook workbook,HSSFSheet sheet, int rowIndex, int colIndex) {
		sheet = workbook.getSheetAt(0);
		 HSSFRow row = sheet.getRow(rowIndex - 1);
		 HSSFCell cell = row.getCell(colIndex - 1);
		return cell;
	}
	
}
